<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
	<meta name="generator" content="Hugo 0.63.2" />
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title>天地维杰网 - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="天地维杰网">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content="天地维杰网 - 天地维杰网" />
    <meta name="description" content="天地维杰网 | 博客 | 软件 | 架构 | Java "> 
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: false, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item menu-item-active">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
    
 <section id="posts" class="posts-expand">

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/learn-about-apollo/" itemprop="url">
        Apollo学习
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2021-02-25">
    2021-02-25
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/middleware" itemprop="url" rel="index">
        <span itemprop="name">middleware</span>
      </a>
      &nbsp; 
    </span>
  
</span>


       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">2844 字 ~6分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    Apollo（阿波罗）是携程框架部门研发的分布式配置中心，能够集中化管理应用不同环境、不同集群的配置，配置修改后能够实时推送到应用端，并且具备规范的权限、流程治理等特性，适用于微服务配置管理场景
    </div>
    
    <div class="post-more-link text-center">
    <a class="btn" href="http://www.shutdown.cn/post/learn-about-apollo/" rel="contents">
      阅读全文 &raquo;
    </a>
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/lvs_keepalive_jenkins2_ha/" itemprop="url">
        lvs&#43;keepalive配置Jenkins2高可用
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2020-02-22">
    2020-02-22
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/linux" itemprop="url" rel="index">
        <span itemprop="name">linux</span>
      </a>
      &nbsp; 
    </span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/cicd" itemprop="url" rel="index">
        <span itemprop="name">cicd</span>
      </a>
      &nbsp; 
    </span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/daily" itemprop="url" rel="index">
        <span itemprop="name">daily</span>
      </a>
      &nbsp; 
    </span>
  
</span>


       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">5569 字 ~12分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    lvs&#43;keepalived部署jenkins2高可用，包括部署步骤，参考文档等等
    </div>
    
    <div class="post-more-link text-center">
    <a class="btn" href="http://www.shutdown.cn/post/lvs_keepalive_jenkins2_ha/" rel="contents">
      阅读全文 &raquo;
    </a>
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/markdown/" itemprop="url">
        markdown语法
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2020-01-19">
    2020-01-19
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/daily" itemprop="url" rel="index">
        <span itemprop="name">daily</span>
      </a>
      &nbsp; 
    </span>
  
</span>


       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">540 字 ~2分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    markdown语法
    </div>
    
    <div class="post-more-link text-center">
    <a class="btn" href="http://www.shutdown.cn/post/markdown/" rel="contents">
      阅读全文 &raquo;
    </a>
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/linux-struct-align-c-packed/" itemprop="url">
        linux中结构体对齐
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="2015-08-03">
    2015-08-03
</time>
</span> 
      

  <span class="post-category" >
  &nbsp; | &nbsp;
  <span class="post-meta-item-icon">
    <i class="fa fa-folder-o"></i>
  </span>
  <span class="post-meta-item-text">分类：</span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/linux" itemprop="url" rel="index">
        <span itemprop="name">linux</span>
      </a>
      &nbsp; 
    </span>
  
    <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
      <a href="http://www.shutdown.cn/categories/c" itemprop="url" rel="index">
        <span itemprop="name">c</span>
      </a>
      &nbsp; 
    </span>
  
</span>


       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">2653 字 ~6分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    以上这个结构体占用内存多少空间呢？也许你会说，这个简单，计算每个类型的大小，将它们相加就行了，以32为平台为例，int类型占4字节，char占用1字节，所以：4 &#43; 3 &#43; 4 = 11，那么这个结构体一共占用11字节空间。好吧，那么我们就用实践来证明是否正确，我们用sizeof运算符来求出这个结构体占用内存空间大小，sizeof(MemAlign)，出乎意料的是，结果居然为12？看来我们错了？
    </div>
    
    <div class="post-more-link text-center">
    <a class="btn" href="http://www.shutdown.cn/post/linux-struct-align-c-packed/" rel="contents">
      阅读全文 &raquo;
    </a>
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/redis-scan%E8%BF%94%E5%9B%9E%E6%95%B0%E6%8D%AE%E9%87%8F%E5%A4%A7%E4%BA%8Elimit%E7%9A%84count%E5%8E%9F%E5%9B%A0%E5%88%86%E6%9E%90/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">6 字 ~1分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    Redis Scan返回数据量大于Limit的Count原因分析 Redis所有的Key都存储在一个大字典中，与JAVA的HashMap类似，是一个一维数组二维链表的结构，key会按算法取模计算的值挂到一维数组对应的值的索引的链表下。如下图：
 scan指令返回的游标就是第一维数组的位置索引，limit参数表示需要遍历的索引数量，不考虑字典扩容缩容的话，遍历将直接按一维数组的下标进行遍历。遍历的结果可能多可能少，因为不是所有的索引位上都会挂接链表，索引位上挂的链表的元素数量也可能有多个。每次遍历会将limit数量的索引位上挂接的所有的链表元素进行模式匹配过滤一次性返回给客户端。
我这次遇到的问题，是我每次通过scan获取匹配元素进行处理，但是为了不影响集群的性能，所以限制每次处理的元素不超过1024个，每次scan的数量限制为256个，但是程序跑着却突破了1024的这个限制，我就很纳闷，为什么我每次只scan256个，竟然会突破1024这个数量的限制，打了断点查看，一次scan竟然scan出来了2100多个元素，而且这2100个元素都是在一个位置上的。这个场景理论上只会在数据量特别大的情况才能够出现。为了找原因，翻redis的文档并没有翻到点上，看scan命令的说明也没看出个所以然来，然后就翻翻书，在《Redis深度历险 核心原理与应用实践》这本书上翻到了自己能够理解的说明。
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/redis4.0%E6%96%B0%E7%89%B9%E6%80%A7%E4%B8%80-memory-command/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">1666 字 ~8分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    Redis4.0新特性(一)-Memory Command  原文地址：https://www.jianshu.com/p/cd2951fa45f4
 Redis4.0版本增加了很多诱人的新特性，在redis精细化运营管理中都非常有用(猜想和antirez加入redislabs有很大关系)；此系列几篇水文主要介绍以下几个新特性的使用和效果。
 Redis Memeory Command:详细分析内存使用情况，内存使用诊断，内存碎片回收；
 PSYNC2:解决failover和从实例重启不能部分同步；PSYNC3已经路上了；
 LazyFree: 再也不用怕big key的删除引起集群故障切换；
 LFU: 支持近似的LFU内存淘汰算法；
 Active Memory Defragmentation：内存碎片回收效果很好(实验阶段）；
 Modules: Redis成为更多的可能（觉得像mongo/mysql引入engine的阶段）；
  Memory Command简介 redis4.0引入新的命令memory, memory命令共有5个子命令； 让我们能更深入要了解redis内部的内存使用情况。 通过memory help命令，可以查看除memory doctor的其他4个子命令； 5个指令简介如下：
 MEMORY USAGE  [SAMPLES ] -&ldquo;Estimate memory usage of key&rdquo; MEMORY STATS -&ldquo;Show memory usage details&rdquo; MEMORY PURGE -&ldquo;Ask the allocator to release memory&rdquo; MEMORY DOCTOR - &ldquo;A better observability on the Redis memory usage.
    </div>
    
    <div class="post-more-link text-center">
    <a class="btn" href="http://www.shutdown.cn/post/redis4.0%E6%96%B0%E7%89%B9%E6%80%A7%E4%B8%80-memory-command/" rel="contents">
      阅读全文 &raquo;
    </a>
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/redis4.0%E6%96%B0%E7%89%B9%E6%80%A7%E4%B8%89-lazy-free/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">537 字 ~3分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    源文地址：https://www.jianshu.com/p/e927e99e650d
 Redis4.0新特性(三)-Lazy Free Redis4.0新增了非常实用的lazy free特性，从根本上解决Big Key(主要指定元素较多集合类型Key)删除的风险。笔者在redis运维中也遇过几次Big Key删除带来可用性和性能故障。 本文分为以下几节说明redis lazy free：
 lazy free的定义 我们为什么需要lazy free lazy free的使用 lazy free的监控 lazy free实现的简单分析  lazy free的定义 lazy free可译为惰性删除或延迟释放；当删除键的时候,redis提供异步延时释放key内存的功能，把key释放操作放在bio(Background I/O)单独的子线程处理中，减少删除big key对redis主线程的阻塞。有效地避免删除big key带来的性能和可用性问题。
我们为什么需要lazy free Redis是single-thread程序(除少量的bio任务),当运行一个耗时较大的请求时，会导致所有请求排队等待redis不能响应其他请求，引起性能问题,甚至集群发生故障切换。
而redis删除大的集合键时，就属于这类比较耗时的请求。通过测试来看，删除一个100万个元素的集合键，耗时约1000ms左右。 以下测试，删除一个100万个字段的hash键，耗时1360ms；处理此DEL请求期间，其他请求完全被阻塞。
删除一个100万字段的hash键 127.0.0.1:6379&gt; HLEN hlazykey (integer) 1000000 127.0.0.1:6379&gt; del hlazykey (integer) 1 (1.36s) 127.0.0.1:6379&gt; SLOWLOG get 1) 1) (integer) 0 2) (integer) 1501314385 3) (integer) 1360908 4) 1) &#34;del&#34; 2) &#34;hlazykey&#34; 5) &#34;127.0.0.1:35595&#34; 6) “&#34; 测试估算，可参考；和硬件环境、Redis版本和负载等因素有关
    </div>
    
    <div class="post-more-link text-center">
    <a class="btn" href="http://www.shutdown.cn/post/redis4.0%E6%96%B0%E7%89%B9%E6%80%A7%E4%B8%89-lazy-free/" rel="contents">
      阅读全文 &raquo;
    </a>
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/redis4.0%E6%96%B0%E7%89%B9%E6%80%A7%E4%BA%8C-psync2/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">813 字 ~4分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    
    Redis4.0新特性(二)-PSYNC2 Redis4.0新特性psync2(partial resynchronization version2)部分重新同步(partial resync)增加版本； 主要解决Redis运维管理过程中，从实例重启和主实例故障切换等场景带来的全量重新同步(full resync)问题。
什么是Redis部分重新同步psync redis部分重新同步：是指redis因某种原因引起复制中断后，从库重新同步时，只同步主实例的差异数据(写入指令），不进行bgsave复制整个RDB文件。
本文的名词规约： 部分重新同步：后文简称psync 全量重新同步：后文简称fullsync redis2.8第一版部分重新同步：后文简称psync1 redis4.0第二版本部分重新同步：后文简称psync2
在说明psync2功能前，先简单阐述redis2.8版本发布的psync1
Redis2.8 psync1解决什么问题 在psync1功能出现前，redis复制秒级中断，就会触发从实例进行fullsync。 每一次的fullsync，集群的性能和资源使用都可能带来抖动；如果redis所处的网络环境不稳定，那么fullsync的出步频率可能较高。 为解决此问题，redis2.8引入psync1, 有效地解决这种复制闪断，带来的影响。
redis的fullsync对业务而言，算是比较“重”的影响；对性能和可用性都有一定危险。 这里列举几个fullsync常见的影响：
1. master需运行bgsave,出现Fork，可能造成master达到毫秒或秒级的卡顿(latest_fork_usec)； 2. redis进程Fork导致Copy-On-Write内存使用消耗(后文简称COW)，最大能导致master进程内存使用量的消耗。 (eg RDB: 5213 MB of memory used by copy-on-write) 3. Redis Slave load RDB过程，会导致复制线程的client output buffer增长很大；增大Master进程内存消耗； 4. Redis保存RDB(不考虑disless replication),导致服务器磁盘IO和CPU(压缩)资源消耗 5. 发送数GB大小的RDB文件,会导致服务器网络出口爆增,如果千兆网卡服务器，期间会影响业务正常请求响应时间(以及其他连锁影响)  psync1的基本实现 redis2.8为支持psync1，引入了replication backlog buffer(后文称：复制积压缓冲区）；
复制积压缓冲区是redis维护的固定长度缓冲队列(由参数repl-backlog-size设置，默认1MB)， master的写入命令在同步给slaves的同时，会在缓冲区中写入一份(master只有1个积压缓冲区，所有slaves共享）。
当redis复制中断后，slave会尝试采用psync, 上报原master runid + 当前已同步master的offset(复制偏移量，类似mysql的binlog file和position)； 如果runid与master的一致，且复制偏移量在master的复制积压缓冲区中还有(即offset &gt;= min(backlog值)，master就认为部分重同步成功，不再进行全量同步。
部分重同步成功，master的日志显示如下： 30422:M 04 Aug 14:33:48.505 * Slave xxxxx:10005 asks for synchronization 30422:M 04 Aug 14:33:48.
    </div>
    
    <div class="post-more-link text-center">
    <a class="btn" href="http://www.shutdown.cn/post/redis4.0%E6%96%B0%E7%89%B9%E6%80%A7%E4%BA%8C-psync2/" rel="contents">
      阅读全文 &raquo;
    </a>
    </div>
    
    <footer class="post-footer"><div class="post-eof"></div></footer>
  </article>

</section>
















<nav class="pagination">
    <a class="extend prev" rel="prev" href="http://www.shutdown.cn/p/13/"><i class="fa fa-angle-left"></i></a>
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/10/">10</a>
        
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/11/">11</a>
        
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/12/">12</a>
        
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/13/">13</a>
        
        
    
        
        
          <span class="page-number current">14</span>
        
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/15/">15</a>
        
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/16/">16</a>
        
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/17/">17</a>
        
        
    
        
        
          <a class="page-number" href="http://www.shutdown.cn/p/18/">18</a>
        
        
    
        
    
        
    
        
    
        
    
        
    
    <a class="extend next" rel="next" href="http://www.shutdown.cn/p/15/"><i class="fa fa-angle-right"></i></a>
</nav>




          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

    <section class="site-overview sidebar-panel  sidebar-panel-active ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
<div class="feed-link motion-element">
<a href="http://www.shutdown.cn/index.xml" rel="alternate" type="application/rss+xml" target="_blank">
    <i class="fa fa-rss"></i>
    RSS 订阅
</a>
</div>

      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" id="motion.page.archive">
  $('.archive-year').velocity('transition.slideLeftIn');
</script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>